home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-02-27 | 2.7 KB | 106 lines | [TEXT/CWIE] |
- /* SK8 © 1997 Apple Computer, Inc.
- This code is protected under the current SK8 License
- See http://sk8.research.apple.com/ for more information
- Apple Research Laboratories
- */
-
-
- import java.awt.*;
- import java.applet.Applet;
-
-
- class imagerenderer extends renderer {
-
- //PROPERTIES AND THEIR GETTERS AND SETTERS.
-
- private String filenameVar;
- private Image currentImage;
- private renderer backgroundrendererVar = sk8.white;
- Applet currentApplet;
-
- public imagerenderer () {
- this.currentImage = null;
- }
-
- public imagerenderer (String s) {
- this.setfilename(s);
- }
-
- public imagerenderer (String s, Applet app) {
- this.setfilename(s, app);
- }
-
- public String filename() {
- return filenameVar;
- }
- public void setfilename(String s) {
- setfilename(s, sk8.currentApplet);
- }
- public void setfilename(String s, Applet app) {
- filenameVar = s;
- currentImage = app.getImage(app.getDocumentBase(), filenameVar);
- currentApplet = app;
- }
-
- public renderer backgroundrenderer() {
- return backgroundrendererVar;
- }
- public void setbackgroundrenderer(renderer r) {
- backgroundrendererVar = r;
- }
-
- private Point absolutepositionVar;
- public Point absoluteposition() {
- return absolutepositionVar;
- }
- public void setabsoluteposition(Point r) {
- absolutepositionVar = r;
- }
-
- public int height() {
- //because java deals with images async'ly, we'll just wait for the
- //image to finish loading, since SK8 deals with these guys sync'ly
- int h = -1;
- while (h == -1){
- h = currentImage.getHeight(sk8.currentApplet);
- }
- return h;
- }
-
- public int width() {
- //because java deals with images async'ly, we'll just wait for the
- //image to finish loading, since SK8 deals with these guys sync'ly
- int w = -1;
- while (w == -1){
- w = currentImage.getWidth(sk8.currentApplet);
- }
- return w;
- }
-
-
- //THE RENDER METHOD
- void render(Graphics g, actor act, Region reg) {
- Rectangle drawrect;
- if (absolutepositionVar != null)
- drawrect = new Rectangle(absolutepositionVar.x, absolutepositionVar.y, 0,0);
- else
- drawrect = act.boundsrect(true);
- // Render a background renderer is one is specified for a non rectangular image
- if (backgroundrendererVar != null)
- backgroundrendererVar.render(g, act, reg);
- // If a proper image is specified, render that
- if ((currentImage != null) && (currentApplet != null))
- reg.drawImageRegion(g,
- currentImage,
- drawrect,
- currentApplet);
- // In the worst case when there is no image and no
- // backgroundRenderer, render white
- else if (backgroundrendererVar == null)
- sk8.white.render(g, act, reg);
-
- }
-
- }
-
-